﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.BusinessRule.System;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.CallRoute;
public partial class CallRoute_Visit_History_Result_List : PageBase
{
    private decimal id = 0;
    private decimal visitid = 0;
    private const string VISIT_ID = "visitid";
    private string NAME = "";
    private string USERNAME = "";
    private string VISITTIME = "";
    private string Remark = "";
    private RouteManager manager = new RouteManager();

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);//去掉页面缓存

        if (Request.QueryString[VISIT_ID] != null)
        {
            decimal.TryParse(Request.QueryString[VISIT_ID], out visitid);
        }

        option.Visible = string.IsNullOrEmpty(Request["type"]);

        VISITS visit = manager.LoadVisits(visitid);
        Person person = new PersonManager().Load(int.Parse(visit.personid.ToString()));
        CUSTOMERS customer = new CustomerManager().Load(visit.CUSTOMERID);
        DataTable callReview = null;// manager.LoadCallReview(visitid).BillDataTable;

        NAME = customer.NAME;
        USERNAME = person.Name;
        VISITTIME = visit.STOPTIME.ToString();
        if (callReview != null)
        //Remark = callReview.CallResult;
        {
            foreach (DataRow dr in callReview.Rows)
            {
                Remark += dr["CallResult"].ToString() + ";";
            }
        }
        id = customer.ID;
        if (!IsPostBack)
        {
            GridPager1.GridView = gvVisit;
            GridPager1.CurrentPage = PageIndex;
            GetVisitHistoryByCustomerID();
            lblVisitHistoryMessage.InnerHtml = "[门店名称:  <a href='../masterdata/customer_view.aspx?target=" + Server.UrlEncode(Request.Url.ToString()) + "&id=" + visit.CUSTOMERID.ToString() + "'>" + NAME + "</a>][巡店督导:  " + USERNAME + "]" + "      [拜访时间:  " + VISITTIME + "]";

            txtRemark.Text = Remark;
        }
    }
    public void GetVisitHistoryByCustomerID()
    {
        DataSet ds = RouteManager.SearchVisitHistoryByCustomerID(id, visitid);
        GridPager1.DataSource = ds.Tables[0];
        GridPager1.BindData();
    }

    protected void gvVisit_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Grid_RowDataBound(sender, e);

            Label lab = new Label();
            if (lab != null)
            {
                Label labName = e.Row.FindControl("Label1") as Label;

                if (e.Row.Cells[7].Text == "&nbsp;" && e.Row.Cells[8].Text == "&nbsp;" && e.Row.Cells[9].Text == "&nbsp;" && e.Row.Cells[10].Text == "&nbsp;" && e.Row.Cells[11].Text == "&nbsp;")
                {
                    labName.Text = "无效拜访";
                    e.Row.Style[HtmlTextWriterStyle.Color] = "red";
                }
                else
                {
                    labName.Text = "有效拜访";
                }
            }
        }
    }

    protected void btnResearch_Click(object sender, EventArgs e)
    {
        
        Response.Redirect("Visit_History_List.aspx"+"?"+Request.QueryString);
    }
}
